home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / gnustuff / minix / update~4.z / update~4 / lib_stdio_fdopen.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-09-06  |  801 b   |  35 lines

  1. /*                f d o p e n
  2.  *
  3.  * Open a stream and associate it with a file descriptor. The
  4.  * file descriptor would typically have been obtained from either
  5.  * a call to open(), dup(), creat() or pipe(). The type of stream
  6.  * (read, write or append) must agree with the mode of the open
  7.  * file.
  8.  *
  9.  * The function returns a pointer to the stream on success and
  10.  * NULL on failure.
  11.  *
  12.  * Patchlevel 1.0
  13.  *
  14.  * Edit History:
  15.  */
  16.  
  17. #include "stdiolib.h"
  18.  
  19. /*LINTLIBRARY*/
  20.  
  21. FILE *fdopen(fd, mode)
  22.  
  23. int        fd;                    /* channel */
  24. CONST char *mode;                /* mode to open */
  25.  
  26. {
  27.   FILE **sp;                /* slot in table */
  28.   short flags;                /* flag settings */
  29.  
  30.   return (sp = _slot((FILE *) NULL)) == NULL ||
  31.          fd != _fopen((CONST char *) NULL, mode, fd, &flags)
  32.     ? NULL
  33.     : (*sp = _file((FILE *) NULL, fd, flags));
  34. }
  35.